<template>
<div class="page workApplyCreate-page" data-page="workApplyCreate" style="z-index: 2;">
	<div class="link-page-nav">
		<a href="#" class="link" @click="$root.backToTab()"> <i class="iconfont icon-zuo"></i>
		</a>
	</div>
	<div class="link-page-top" style="padding-bottom: 17px;">
		<div class="link-page-title">创建作业申请</div>
	</div>
	<div class="page-content" style="padding-bottom: 120px;">
		<div style="margin: 20px;" >
			<div class="page-workType" id="workApplyCreate-workType_{{getNewId}}">
				<div class="page-content-item-title">
					<span>作业类型</span>
				</div>
				<div class="page-workType-button" id="workTypeList_{{getNewId}}">
					
				</div>
			</div>
			<div class="page-inline">
				<div class="inItem">
					<div>业主单位</div>
					<a href="#" id="workApply_select_org_{{getNewId}}">
						<span id="workApply_org_{{getNewId}}">选择作业所在的业主单位</span>
						<span><i class="iconfont icon-jiantou"></i></span>
					</a>
				</div>
				<div class="inItem">
					<div>开始时间</div>
					<a href="#" @click="openTime(1)">
						<span id="workApply_startTime_{{getNewId}}">选择开始时间</span>
						<span><i class="iconfont icon-jiantou"></i></span>
					</a>
				</div>
				<div class="inItem">
					<div>结束时间</div>
					<a href="#" @click="openTime(2)">
						<span id="workApply_endTime_{{getNewId}}">选择结束时间</span>
						<span><i class="iconfont icon-jiantou"></i></span>
					</a>
				</div>
				<div class="inItem">
					<div>作业区域</div>
					<a href="#" @click="selectBuilding">
						<span id="workApply_area_{{getNewId}}">选择作业区域</span>
						<span><i class="iconfont icon-jiantou"></i></span>
					</a>
				</div>
				<div class="inItem">
					<div>作业说明 <span style="float: right;"><i class="iconfont icon-yuyin" id="speechInputDetails_{{getNewId}}"></i></span></div>
					<input type="text" class="job-description" id="workDesc_{{getNewId}}" placeholder="简洁描述作业内容，尝试用语音输入更便捷">
				</div>
				<div class="itemTask">
					<div class="listTitle">
						相关任务 <label>(非必选)</label>
					</div>
					<div>
						<ul class="taskList" id="workApply_taskList_{{getNewId}}">
								
						</ul>
					</div>
					
					<div class="inItem-button" @click="addRelateTask">
						<span><i class="iconfont icon-jia"></i> <span>添加维保任务</span>
						</span>
					</div>
				</div>
				<div class="inItem" id="workApply-button_{{getNewId}}">
					<div>作业人</div>
					<div class="inItem-button-input">
						<div class="range-icon"></div>
						<input type="hidden" value="1"> <span>与维保任务责任人同步</span>
					</div>
					<div class="inItem-button-input active">
						<div class="range-icon active"></div>
						<input type="hidden" value="0"> <span>手动添加</span>
					</div>
					<div id="operators_{{getNewId}}">
						<span id="workOnwerSpan_{{getNewId}}">
							
						</span>
						<div class="page-img-item">
							<div class="itembg item-icon" @click="selectWorOwner">
								<i class="iconfont icon-APPicon_tianjia"></i>
							</div>
							<p>&nbsp;</p>
						</div>
					</div>
				</div>
			</div>
			<div style="padding-top: 25px;">
				<div class="page-content-item-title">
					<span>审批人</span>
				</div>
				<div class="">
					<span id="applicantOnwerSpan_{{getNewId}}">
						
					</span>
					<div class="page-img-item">
						<div class="itembg item-icon" @click="selectApplyOwner">
							<i class="iconfont icon-APPicon_tianjia"></i>
						</div>
						<p>&nbsp;</p>
					</div>
				</div>
			</div>
			<div class="page-buttom-bottom" @click="submitCreate">
				<div class="submitBtn">创建</div>
			</div>
		</div>
	</div>
</div>
</template>
<style scoped>
	.ownerName{
		font-size: 14px;
		color: rgba(51, 51, 51, 1);
		font-weight: 550;
		overflow: hidden;
		text-overflow:ellipsis;
		white-space: nowrap;
	}
	.taskList{
		margin-top: 15px !important;
	}
	.taskList li{
		border: 1px solid rgba(225,225,225,.9);
		box-shadow: 0 1px 10px 0 rgba(181,200,206,.5);
		border-radius: 6px;
		margin-bottom: 20px;
		background: #f5f5f5;
		padding: 0 20px;
	}
	.taskList li a{
			color: #2196f3;
	}
	.taskList .taskStatus {
		font-size: 14px;
		color: #2471CA;
	}
	.taskList .taskTitle {
		max-width: 100%;
		margin: 9px 0px;
		font-size: 17px;
		color: #333;
		font-weight: 600;
		margin-top: 5px;
		margin-bottom: 5px;
	}
	.taskList .OperationCycleTitle {
		color: #999;
		font-size: 14px;
	}
	.taskList .OperationCycle {
		margin-left: 5px;
		color: #333333;
	}
	.page-inline .itemTask {
		margin-top: 39px;
	}
	.page-inline .itemTask .listTitle{
		font-size: 17px;
		color: rgba(51, 51, 51, 1);
		font-weight: 600;
	}
	.page-inline .itemTask label{
		font-size: 14px;
		color: rgba(51, 51, 51, 1);
		font-weight: 400;
	}
	.taskList .item-subtitle{
		position: relative;
		overflow: hidden;
		white-space: nowrap;
		max-width: 100%;
		text-overflow: ellipsis;
		color: #999;
		margin-bottom: 5px;
		font-size: 14px;
	}
	.taskList .closeTask{
		float: right;
		margin-top: 5px;
		COLOR: #7b7878;
	}
	.itemTask .inItem-button {
		height: 40px;
		border: 1px solid rgba(208, 208, 208, 1);
		border-radius: 4px;
		font-size: 14px;
		font-family: PingFangSC-Regular;
		font-weight: 400;
		color: rgba(36, 113, 202, 1);
		line-height: 35px;
		text-align: center;
		margin-top: 25px;
	}
	.workApplyCreate-page  .page-img-item{
		width: 23% !important;
	}
</style>
<script>
	return {
		mounted() {
			var self = this;
    		self.taskId = this.$route.params.taskId;
    		self.taskInfo = this.$route.params.taskInfo;
        },
		data : function() {
			return {
				selectOptionOrg : 0,
				taskStartTime:"",
				taskEndTime:"",
				taskArea:"",
				workDesc:"",
            	touBType:[],
            	workOwnerType : 0,
            	workType : "",
            	selectOptionIndex1:"",
            	selectOptionType:"",
            	selectOptionIndex2:"",
            	selectOptionType2:"",
            	currentOrgId:"",
            	relateTaskList:{},
            	taskArray:[],
            	getNewId: (new Date()).getTime(),
			}
		},
		methods : {
			backToRefresh:function(){

			},
			//提交
			submitCreate:function(){
				var self = this;
				self.workDesc = $("#workDesc_"+self.getNewId).val();
				if (self.currentOrgId == "") {
	                app.methods.showToastCenter('请添加业主单位');
	                return;
	            }
				if (self.taskStartTime == "") {
	                app.methods.showToastCenter('请添加开始时间');
	                return;
	            }
				if (self.taskEndTime == "") {
	                app.methods.showToastCenter('请添加结束时间');
	                return;
	            }
				//self.taskArea="2170,2175";//美佳说了，是通用的页面，需要封装到时候她统一写 先写假数据
				if (self.taskArea == "") {
	                app.methods.showToastCenter('请添加作业区域');
	                return;
	            }
				if (self.workDesc == "") {
	                app.methods.showToastCenter('请添加作业说明');
	                return;
	            }

				var applicantOnwer = common.getObjValJoin($("#applicantOnwerSpan_"+self.getNewId+" input[name='applicantOnwer']"));//审批人
				var workOnwer = common.getObjValJoin($("#workOnwerSpan_"+self.getNewId+" input[name='workOnwer']"));//作业人
				if(self.workOwnerType==0 && workOnwer==""){
					app.methods.showToastCenter('请添加作业人');
	                return;
				}
				
				if (applicantOnwer == "") {
	                app.methods.showToastCenter('请添加审批人'); 
	                return;
	            }
				
				var relateTaskIds="";
				for (var key in self.relateTaskList) {
					relateTaskIds+=key+",";
				}
				relateTaskIds = relateTaskIds.substring(0, relateTaskIds.lastIndexOf(','));
				
				//作业申请-创建作业申请
				Dao.addWorkApply({
					orgId:self.currentOrgId,//业主单位编码
					type: self.workType,//	作业类型,字典表获取
					area :self.taskArea,//作业区域，fbsid 多个逗号分隔
					workDesc : self.workDesc,//作业说明
					createAccount : userInfor.accountName,//
					userName : userInfor.accountName,
					account : userInfor.accountName,
					deviceId : appKeyObj.deviceId,
					relateTaskIds :relateTaskIds,//相关任务id,多个逗号分隔
					workAccounts : workOnwer,//作业人, 多个逗号分隔
					isMaintainAccount : self.workOwnerType,//是否与维保责任人同步，0表示不同步，1表示同步
					beginTimeStr : self.taskStartTime,//开始时间
					endTimeStr : self.taskEndTime,//结束时间
					approvalAccounts : applicantOnwer,//审批人, 多个逗号分隔
                },function(data) {
                	   app.methods.showToastCenter('操作成功');
           	 		   app.methods.backToTab();
                });
			},
			htmlPage : function() {
				var self = this;
				// 作业类型选择
				jQuery("#workApplyCreate-workType_"+self.getNewId+" .checkItem").off().click(function() {
					$(this).parent().find(".checkItem label").removeClass("checked");
					$(this).find("label").addClass("checked");
					// 获取被选中的作业类型
					var typeId = $("#workApplyCreate-workType_"+self.getNewId+" .checkItem").find(".checked").prev().val();
					self.workType=typeId;
				});

				// 获取被选中的作业类型
				var typeId = $("#workApplyCreate-workType_"+self.getNewId+" .checkItem").find(".checked").prev().val();
				self.workType=typeId;

				// 作业人操作
				jQuery("#workApply-button_"+self.getNewId+" .inItem-button-input").off().click(function() {
					if ($(this).find("input").val() == "0") { // 手动添加
						$(this).parent().find(".active").removeClass("active");
						$(this).addClass("active");
						$(this).find(".range-icon").addClass("active");
						$("#operators_"+self.getNewId).css("display", "");
						self.workOwnerType=0;
					} else {
						// self.taskArray
						if(self.relateTaskList.length==0){
							app.methods.showToastCenter('请先添加维保任务');
			                return;
						}else{
							$(this).parent().find(".active").removeClass("active");
							$(this).addClass("active");
							$(this).find(".range-icon").addClass("active");
							self.workOwnerType=1;
							$("#operators_"+self.getNewId).css("display", "none");//与维保任务责任人同步
						}
					}
				});
			},
			//初始化联网单位
			workApplyInitOrg : function(){
				var self = this;
				if (userInfor.isMuilUnitUser  == 0) {
					self.currentOrgId = userInfor.organizationIds;
					jQuery("#workApply_org_"+self.getNewId).html(single_OrgName);
					$("#workApply_org_"+self.getNewId).next().remove();
	            }else{
	              //多联网单位
	              jQuery("#workApply_select_org_"+self.getNewId).show().click(function(e) {
	                   loadSelectUnitFunc(function(data){
	                       if(self.selectOptionOrg != data.orgId){
	                           self.selectOptionOrg = data.orgId;
	                           self.currentOrgId=data.orgId;
	                           jQuery("#workApply_org_"+self.getNewId).html(data.orgName);
	                       } else {
	                           self.selectOptionOrg = 0;
	                           if (single_Orgid == "") {
	                             self.currentOrgId=userInfor.organizationIds;
	                           } else {
	                             self.currentOrgId=single_Orgid;
	                           }
	                       }
	                   },self.selectOptionOrg);
	              });
	           	}
				
			},
	        //选择责任人
	        selectWorOwner:function(){
				var self = this;
				self.selectOptionIndex1 = null;
				self.selectOptionType = null;
				if(!self.currentOrgId || self.currentOrgId.toString().split(",").length != 1){
					app.methods.showToastCenter('请先添加业主单位');
					return;
				}
				getFourTypeUser(self.currentOrgId,function(data){
					//这里是选择责任人之后的回调
					// if(data.type == 4){
					//   self.maintainAccount = '';
					// }else{
					//   self.maintainAccount = data.index;//账号
					// }
					self.maintainAccount = data.index;
					var userHeadUrl = picPeopleNo(data.headUrl);//用户头像
					if($("#workOnwer_"+data.index+"_"+self.getNewId).length==0){
						$("#workOnwerSpan_"+self.getNewId).append(`
								<div class="page-img-item" id="workOnwer_`+data.index+`_`+self.getNewId+`">
								<input type="hidden" name="workOnwer" id="workAccount_`+data.index+`_`+self.getNewId+`" value="`+data.index+`">
									<div class="item">
										<img alt="" src="`+userHeadUrl+`">
										<p class="ownerName">`+data.name+`</p>
									</div>
								</div>
						`);
						jQuery("#workOnwer_"+data.index+"_"+self.getNewId).off('click').on('click',{'data':"#workOnwer_"+data.index+"_"+self.getNewId},function(e) {
							self.delAccount(e.data.data);
						});
					}
				},self.selectOptionIndex1,self.selectOptionType);
	        },
	        //清除责任人相关参数
	        cleanUser:function(){
	            var self = this;
	            self.selectOptionIndex1 = null;
	            self.selectOptionType = null;
	            self.maintainAccount = "";
	            jQuery("#select_owner_"+self.getNewId).removeClass('select-active').html("选择责任人");
	        },
	     	//选择审批人
	        selectApplyOwner:function(){
				var self = this;
				self.selectOptionIndex1 = null;
				self.selectOptionType = null;
				if(!self.currentOrgId || self.currentOrgId.toString().split(",").length != 1){
					app.methods.showToastCenter('请先添加业主单位');
					return;
				}
				getFourTypeUser(self.currentOrgId,function(data){
					//这里是选择审批人人之后的回调
					//维保公司
					// if(data.type == 4){
					//   self.maintainAccount = '';
					// }else{
					//   self.maintainAccount = data.index;//账号
					// }
					self.maintainAccount = data.index;
					var userHeadUrl = picPeopleNo(data.headUrl);//用户头像
					if($("#applicantOnwer_"+data.index + "_" + self.getNewId).length==0){
						$("#applicantOnwerSpan_"+self.getNewId).append(`
								<div class="page-img-item" id="applicantOnwer_`+data.index+ `_` + self.getNewId + `">
									<input type="hidden"  name="applicantOnwer"  id="applicantAccount_`+data.index+`_`+self.getNewId+`" value="`+data.index+`">
									<div class="item">
										<img alt="" src="`+userHeadUrl+`">
										<p class="ownerName">`+data.name+`</p>
									</div>
									<i class="iconfont icon-jiantou-you" style="float: right;margin-top: 20px;color:#999999;"></i>
								</div>
						`);
						jQuery("#applicantOnwer_"+data.index + "_" + self.getNewId).off('click').on('click',{'data':"#applicantOnwer_"+data.index+"_"+self.getNewId},function(e) {
							self.delAccount(e.data.data);
						});
					}
				},self.selectOptionIndex2,self.selectOptionType2);
	        },
	        delAccount:function(obj){
	        	$(obj).remove();
	        },
	        delTask:function(id){
	        	var self = this;
	        	$("#taskItem_"+id+"_"+self.getNewId).remove();
	        	delete self.relateTaskList[id];
	        	for(var i=0;i<self.taskArray.length;i++){
	        		if(self.taskArray[i].id==id){
	        			self.taskArray.splice(i,1);
	        		}
	        	}
	        	
	        	if(self.taskArray.length==0){
	        		var isSynObj = "#workApply-button_"+self.getNewId+" .inItem-button-input";
	        		$(isSynObj).parent().find(".active").removeClass("active");
	        		$(isSynObj).find(".range-icon").removeClass("active");
	        		$("#operators_"+self.getNewId).css("display", "");
	        		self.workOwnerType=0;
	        		$($(isSynObj)[1]).addClass("active");
	        		$($(isSynObj)[1]).find(".range-icon").addClass("active");
	        	}
	        },
	        //获取作业的类型
	        getWorkApplyType:function(){
	        	var self = this;
	        	//类型
	            Dao.getDict({
	               code:94,
	            },function(data) {
	               if (data.dictValueObj&&data.dictValueObj.length>0){
	            	   var dictValueArr = data.dictValueObj;
	                   for (var i = 0;i < dictValueArr.length > 0;i++){
	                        var obj = {};
	                        obj.id= dictValueArr[i].dictKey;
	                        obj.name= dictValueArr[i].dictValue;
	                        var marginCss ="style='margin-left: 3%;'";
	                        if(i%3==0){
	                        	marginCss="";
	                        }
	                        var classChek="";
	                        if(i==0){
	                        	classChek = "class='checked'";
	                        }
	                        $("#workTypeList_"+self.getNewId).append(`
	                        	<div class="checkItem" `+marginCss+`>
	        						<input type="hidden" id="normal" name="checkRadio" value="`+dictValueArr[i].dictKey+`">
	        						<label name="normal" `+classChek+` for="normal">`+dictValueArr[i].dictValue+`</label>
	        					</div>
	                        `);
	                   }
	                   self.htmlPage();
	               }
	            });
	        },
			openTime : function(type){
				var self = this;
				if(type == 1) {
					loadSelectedDate_Fn(1,function(data){
						if(self.taskEndTime && (new Date(data.singleDate.replace(/-/g,"\/")))>(new Date(self.taskEndTime.replace(/-/g,"\/")))){
							app.methods.showToastCenter('开始时间不能大于结束时间');
			                return;
						}
						$("#workApply_startTime_"+self.getNewId).html(data.singleDate);
				    	self.taskStartTime=data.singleDate;
					});
				} else {
					loadSelectedDate_Fn(1,function(data){
						if(self.taskStartTime && (new Date(self.taskStartTime.replace(/-/g,"\/")))>(new Date(data.singleDate.replace(/-/g,"\/")))){
							app.methods.showToastCenter('结束时间不能小于开始时间');
			                return;
						}
						$("#workApply_endTime_"+self.getNewId).html(data.singleDate);
				    	self.taskEndTime=data.singleDate;
					});
				}
				
			},
			initTbPiker: function () {
                var self = this;
                $("#speechInputDetails_"+self.getNewId).click(function (e) {
                    //第二个参数是否需要保存语音
                    native.startVoice("workDesc_"+self.getNewId, false);
                });
            },
            //语音输入回调
            voiceCollectionData: function (voiceStr, componentId) {
                var text = $("#" + componentId).val();
                if (!voiceStr || "" === voiceStr.trim()) {
                    app.methods.showToastCenter("未能识别您说的语音,请重试。");
                } else {
                    $("#" + componentId).val(text + voiceStr);
                }
            },
			//获取作业申请任务详情
            getWorkApplyDetail:function(){
                var self = this;
                var param = {
                		id: self.taskId,
                        status:1
                      };
                Dao.getWorkApplyDetail(param, function (data,total) {
                    if (data){
                    	var typeName = data.typeName;
                    	var approvalDetailList = data.approvalDetail;//审批详情
                    	var approvalCreateAccountName = data.createAccountName;
                    	var workCreateAccount  = data.createAccount;
                    	var approvalAccounts = data.approvalAccounts;//审批人账号
                    	var approvalCreateTime= data.createTime;
                    	var areaNames = data.areaName;//作业区域
                    	var areaId =	data.area;//作业区域编码
                    	var taskDetailStep=data.step;
                    	var workApplyType=data.type;

                    	var beginTime = data.beginTime;
       	                if(beginTime){
       	               		 beginTime =moment(beginTime).format('YYYY-MM-DD HH:mm:ss');
       	                }
       	             	var endTime = data.endTime;
    	                if(endTime){
    	                	endTime =moment(endTime).format('YYYY-MM-DD HH:mm:ss');
    	                }

    	                $("#workTypeList_"+self.getNewId).find(".checkItem label").removeClass("checked");
						$("#workTypeList_"+self.getNewId+" input[value='"+workApplyType+"']").next().addClass("checked");
						self.workType=workApplyType;	//设备赋值
						 
    	                $("#workApply_org_"+self.getNewId).html(data.orgName);
    	                self.currentOrgId=data.orgId;
						 
    	                $("#workApply_startTime_"+self.getNewId).html(beginTime);
    	                self.taskStartTime=beginTime;
    	                $("#workApply_endTime_"+self.getNewId).html(endTime);
    	                self.taskEndTime=endTime;
    	                $("#workDesc_"+self.getNewId).val(data.workDesc);
    	                self.workDesc=data.workDesc;
    	                
    	                self.taskArea = areaId;
    					$("#workApply_area_"+self.getNewId).html(areaNames);
    	                
    	                //$("#workApply_area").html(data.areaName);
    	                /**是否与维保人同步   start*/
    	                var isSynAccount = data.isMaintainAccount;//是否与维保人同步，0表示不同步，1表示同步
    	                var isSynObj ="#workApply-button_"+self.getNewId+" .inItem-button-input";
    	                $(isSynObj).parent().find(".active").removeClass("active");
    	                $(isSynObj).find(".range-icon").removeClass("active");
    	                if(isSynAccount==1){
    	                	self.workOwnerType=1;
    						$("#operators_"+self.getNewId).css("display", "none");//与维保任务责任人同步
    	                	$($(isSynObj)[0]).addClass("active");
    	                	$($(isSynObj)[0]).find(".range-icon").addClass("active");
    	                }else{
    	                	$("#operators_"+self.getNewId).css("display", "");
    						self.workOwnerType=0;
    						$($(isSynObj)[1]).addClass("active");
    						$($(isSynObj)[1]).find(".range-icon").addClass("active");
    	                }

    	                
    	                var relateTaskDetailList = data.relateTaskDetail;//相关任务集合
    	                if(relateTaskDetailList){
                    		for(var i=0;i<relateTaskDetailList.length;i++){
                   				 if(relateTaskDetailList[i]!=""){
									self.taskArray.push(
										{
											startTime:moment(relateTaskDetailList[i].startTime).format('YYYY/MM/DD'),
											endTime: moment(relateTaskDetailList[i].endTime).format('YYYY/MM/DD'),
											id:relateTaskDetailList[i].id,
											maintainType:relateTaskDetailList[i].maintainType,
											name:relateTaskDetailList[i].name,
											status:relateTaskDetailList[i].status
										}
									);
                   				    var taskDetail = relateTaskDetailList[i];
	                   				var startTime = taskDetail.startTime;
	                   				var relateTaskId = taskDetail.id;
	                   				var status = taskDetail.status;//任务状态 1：未开始 2：进行中 3：已结束
	                   				var maintainType = taskDetail.maintainType;//维保类型 1 维保巡查任务 2保养任务 3测试任务 4联动测试任务
	               	                if(startTime){
	               	                	startTime =moment(startTime).format('YYYY/MM/DD HH:mm');
	               	                }
	               	             	var endTime = taskDetail.endTime;
	               	                if(endTime){
	               	                	endTime =moment(endTime).format('YYYY/MM/DD HH:mm');
	               	                }
	               	           		//把字符串格式转化为日期类
	               	             	var endDate = new Date(Date.parse(endTime));
	               	             	var curTime =new Date();
                    			 	//复制申请任务的时只复制未完成和未到期的任务
                    			 	if(status!=3 && curTime<endDate){
		               	                if(status==1){
		               	                	status = "未开始";
		               	                }else if(status==2){
		               	                	status = "进行中";
		               	                }else if(status==3){
		               	                	status = "已结束";
		               	                }
		               	                var taskDetailUrl = "";//任务详情地址
		               	                if(maintainType==1){
		               	                	taskDetailUrl="/maintainInspectDetail/"+relateTaskId+"/0/";
		               	                }else if(maintainType==2){
		               	                	taskDetailUrl="/maintainDetail/"+relateTaskId+"/0/";
		               	                }else if(maintainType==3){
		               	                	taskDetailUrl="/singleTestDetail/"+relateTaskId+"/0/";
		               	                }else if(maintainType==4){
		               	                	taskDetailUrl="/linkTestDetail/"+relateTaskId+"/";
		               	                }
		                    			 $("#workApply_taskList_"+self.getNewId).append(`
		                    					 <li id="taskItem_`+relateTaskId+`_`+self.getNewId+`">
		                    					 	<i class="iconfont closeTask" id="taskClose_`+relateTaskId+`_`+self.getNewId+`">X</i>
		                    		        		<a href="`+taskDetailUrl+`" data-view=".view-main">
		                    		        			<div class="item-inner" style="padding: 0;padding-top: 5px;">
		                    		                          <div class="taskStatus">`+status+`</div>
		                    		                          <div class="taskTitle">`+taskDetail.name+`</div>
		                    		                          <div class="item-subtitle">
		                    		                          	<div class="float-left OperationCycleTitle">作业周期 </div>
		                    		                          	<div class="float-left OperationCycle">`+startTime+` ~ `+endTime+`</div>
		                    		                          </div>
		                    	                      	</div>
		                    		        		</a>
		                    		        	</li>
		                    			 `);
		                    			 
		                    			 jQuery("#taskClose_"+relateTaskId+"_"+self.getNewId).off('click').on('click',{'data':relateTaskId},function(e) {
		                                  		self.delTask(e.data.data);
		 		                         });

		                    			 var obj = {};
		                                 obj.id= relateTaskId;
		                                 obj.name= taskDetail.name;
		                                 obj.status = taskDetail.status;
		                                 obj.maintainType = maintainType;
		                                 obj.startTime= startTime;
		                                 obj.endTime= endTime;
		                                 self.relateTaskList[relateTaskId]=obj;
                    			 	}
                   				 }
                   			
                   			}
                    	}
    	                
    	                var usersArr = data.workAccount;//任务责任人名称
    	                if(usersArr){
    	                	for (var key in usersArr) {
	                   			 if(usersArr[key]!=""){
	                   				var userHeadUrl = picPeopleNo(usersArr[key].headUrl);//用户头像
	                   				 $("#workOnwerSpan_"+self.getNewId).append(`
	 		                        		<div class="page-img-item" id="workOnwer_`+usersArr[key].account+`_`+self.getNewId+`">
	 		                        		<input type="hidden" name="workOnwer" id="workAccount_`+usersArr[key].account+`_`+self.getNewId+`" value="`+usersArr[key].account+`">
	 											<div class="item">
	 												<img alt=""	src="`+userHeadUrl+`">
													<p class="ownerName">`+usersArr[key].name+`</p>
	 											</div>
	 										</div>
	 		                        `);
	 		                        jQuery("#workOnwer_"+usersArr[key].account+"_"+self.getNewId).off('click').on('click',{'data':"#workOnwer_"+usersArr[key].account+"_"+self.getNewId},function(e) {
	                                  		self.delAccount(e.data.data);
	 		                        });
	                   			 }
                   			}
                    	}
    	                
    	                //审批人
                    	if(approvalDetailList){
                    		for(var i=0;i<approvalDetailList.length;i++){
	                   			 if(approvalDetailList[i]!=""){
	                   				    var approvalDetai = approvalDetailList[i];
	                   					var approvalAccountName = approvalDetai.approvalAccountName;//审批人姓名
	                   					var applyAccount = approvalDetai.approvalAccount;//审批人账号
	                   					var approvalAccountHeadUrl = picPeopleNo(approvalDetai.approvalAccountHeadUrl);//审批人头像
	                   				   $("#applicantOnwerSpan_"+self.getNewId).append(`
	 		                        		<div class="page-img-item" id="applicantOnwer_`+applyAccount+`_`+self.getNewId+`">
	 		                        			<input type="hidden"  name="applicantOnwer"  id="applicantAccount_`+applyAccount+`_`+self.getNewId+`" value="`+applyAccount+`">
	 											<div class="item">
	 												<img alt="" src="`+approvalAccountHeadUrl+`">
													<p class="ownerName">`+approvalAccountName+`</p>
	 											</div>
            									<i class="iconfont icon-jiantou-you" style="float: right;margin-top: 20px;color:#999999;"></i>
	 										</div>
	 		                          `);
	 		                          jQuery("#applicantOnwer_"+applyAccount+"_"+self.getNewId).off('click').on('click',{'data':"#applicantOnwer_"+applyAccount+"_"+self.getNewId},function(e) {
	                                     	self.delAccount(e.data.data);
	                                  });
	                   			 }
                   			}
                    	}
                    }
                });
            },
            //跳转到添加维保任务页面
            addRelateTask:function(){
            	var self = this;
            	if (self.currentOrgId == "") {
	                app.methods.showToastCenter('请先添加业主单位');
	                return;
	            }
            	var taskIdArr = [];
            	for (var i=0;i<self.taskArray.length;i++) {
            		taskIdArr[i] = self.taskArray[i].id;
            	}
            	var taskIds = 0;
            	if(self.taskArray.length>0){
            		taskIds = taskIdArr.join(",")
            	}
            	app.router.navigate("/relateTaskList/"+taskIds+"/"+self.currentOrgId+"/");
            },
            //添加维保任务回调
            addRelateTaskBak:function(taskList){
            	var self = this;
            	for (var key in taskList) {
            		if(self.relateTaskList[key]==null){
            			self.relateTaskList[key]=taskList[key];
            			self.taskArray.push(taskList[key]);
            		}
            	}
            	self.taskArray.sort(function (a, b) {
            		 return Date.parse(a.startTime) - Date.parse(b.startTime);
            	});

            	$("#workApply_taskList_"+self.getNewId).empty();
            	for (var i=0;i<self.taskArray.length;i++) {
            			var taskVo = self.taskArray[i];
            			var maintainType = taskVo.maintainType;
            			var taskDetailUrl = "";//任务详情地址
       	                if(maintainType==1){
       	                	taskDetailUrl="/maintainInspectDetail/"+taskVo.id+"/0/";
       	                }else if(maintainType==2){
       	                	taskDetailUrl="/maintainDetail/"+taskVo.id+"/0/";
       	                }else if(maintainType==3){
       	                	taskDetailUrl="/singleTestDetail/"+taskVo.id+"/0/";
       	                }else if(maintainType==4){
       	                	taskDetailUrl="/linkTestDetail/"+taskVo.id+"/";
       	                }
       	             	var status = taskVo.status;
       	             	if(status==1){
       	             		status ="未开始";
       	             	}else if(status==2){
       	             		status ="进行中";
       	             	}else if(status==3){
       	             		status ="已结束";
       	             	}
            			 $("#workApply_taskList_"+self.getNewId).append(`
            					 <li id="taskItem_`+taskVo.id+`_`+self.getNewId+`">
            					 	<i class="iconfont closeTask" id="taskClose_`+taskVo.id+`_`+self.getNewId+`">X</i>
            		        		<a href="`+taskDetailUrl+`" data-view=".view-main">
            		        			<div class="item-inner" style="padding: 0;padding-top: 5px;">
            		                          <div class="taskStatus">`+status+`</div>
            		                          <div class="taskTitle">`+taskVo.name+`</div>
            		                          <div class="item-subtitle">
            		                          	<div class="float-left OperationCycleTitle">作业周期 </div>
            		                          	<div class="float-left OperationCycle">`+taskVo.startTime+` ~ `+taskVo.endTime+`</div>
            		                          </div>
            	                      	</div>
            		        		</a>
            		        	</li>
            			 `);
            			 
            			 jQuery("#taskClose_"+taskVo.id+"_"+self.getNewId).off('click').on('click',{'data':taskVo.id},function(e) {
                          		self.delTask(e.data.data);
	                     });
            	}
            },
          	//选择建筑物
            selectBuilding:function(){
            	var self = this;
            	if (self.currentOrgId == "") {
	                app.methods.showToastCenter('请先添加业主单位');
	                return;
	            }
            	loadSelectBuildFun(self.currentOrgId,function(data){
            		self.taskArea = data.buildId;
					$("#workApply_area_"+self.getNewId).html(data.buildName);
				});
            },
		},
		on : {
			pageInit : function(e, page) {
				var self = this;
				self.initTbPiker();
				self.getWorkApplyType();
				self.workApplyInitOrg();
				//复制创建
				if(self.taskId>0 && self.taskInfo==0){
					self.getWorkApplyDetail();
				}else if(self.taskId>0 && self.taskInfo!=0){
					//详情页入口创建
					var jsonTaskInfo = JSON.parse(self.taskInfo);
					self.addRelateTaskBak(jsonTaskInfo);
				}
			}
		}
	}
</script>